<?
function paging($table,$act,$cur_page,&$total,&$start,$limit=30,$numpage=5)
{
	if($cur_page=="") $cur_page=1;
	$start=($cur_page-1)*$limit;
	$q = query("select * from $table;");
	$total=ceil(numrows($q)/$limit);
	$startlist=($cur_page-(int)(($numpage-1)/2)<=0?1:$cur_page-(int)(($numpage-1)/2));
	$endlist=($startlist+$numpage-1>$total?$total:$startlist+$numpage-1);
	if($startlist>1) $listpage[]=array("link" => "./?act=$act&page=".($startlist-1), "title" => "<<");

	for($i=$startlist; $i<=$endlist; $i++)
	{
		$listpage[]=array("link" => "./?act=$act&page=$i", "title" => $i);
	}
	if($endlist<$total) $listpage[]=array("link" => "./?act=$act&page=".($endlist+1), "title" => ">>");
	return $listpage;
}
function pagingwhere($table,$where,$act,$link,$cur_page,&$total,&$start,$limit=30,$numpage=5)
{
	if($cur_page=="") $cur_page=1;
	$start=($cur_page-1)*$limit;
	$q = query("select * from $table where $where;");
	$total=ceil(numrows($q)/$limit);
	$startlist=($cur_page-(int)(($numpage-1)/2)<=0?1:$cur_page-(int)(($numpage-1)/2));
	$endlist=($startlist+$numpage-1>$total?$total:$startlist+$numpage-1);
	if($startlist>1) $listpage[]=array("link" => "./?act=$act&$link&page=".($startlist-1), "title" => "<<");

	for($i=$startlist; $i<=$endlist; $i++)
	{
		$listpage[]=array("link" => "./?act=$act&$link&page=$i", "title" => $i);
	}
	if($endlist<$total) $listpage[]=array("link" => "./?act=$act&$link&page=".($endlist+1), "title" => ">>");
	return $listpage;
}
?>